home *** CD-ROM | disk | FTP | other *** search
- // gauge.cnh
-
- // Init func Predeclaration
- func Gui_Component NewDefaultGaugeCompositeV(i32x _iHeight);
- func Gui_Component NewGaugeCompositeV(Menu_Material _pGaugeMaterial, Menu_Material _pSliderMaterial, i32x _iHeight);
- func Gui_Component NewDefaultGaugeCompositeH(i32x _iWidth);
- func Gui_Component NewGaugeCompositeH(Menu_Material _pGaugeMaterial, Menu_Material _pSliderMaterial, i32x _iWidth);
- //func Gui_Component InitGaugeCompositeCommon(Menu_Material _pGaugeMaterial, Menu_Material _pSliderMaterial, i32x _iWidth);
-
- func Gui_Component NewGaugeV(Menu_Material _pMaterial, i32x _iWidth, i32x _iHeight);
- func Gui_Component NewGaugeH(Menu_Material _pMaterial, i32x _iWidth, i32x _iHeight);
- func Gui_Component InitGaugeCommon(Gui_Component _component,Menu_Material _pMaterial, i32x _iWidth, i32x _iHeight);
-
- func void GaugeCompositeV_SldChange(Gui_Component _psource, f32x _fValue);
- func void GaugeCompositeH_SldChange(Gui_Component _psource, f32x _fValue);
- func void GaugeComposite_OnEnable();
- func void GaugeComposite_OnDisable();
-
- func void GaugeCompositeV_OnGaugeResize(i32x _iSize);
- func void GaugeCompositeH_OnGaugeResize(i32x _iSize);
- func void Gauge_OnGaugeResizeH(i32x _iWidth, i32x _iHeight);
- func void Gauge_OnGaugeResizeV(i32x _iWidth, i32x _iHeight);
-
- func void Gauge_SetColor(i32x _iColor);
- func void GaugeV_OnGaugeValue(f32x _fValue);
- func void GaugeH_OnGaugeValue(f32x _fValue);
- func void GaugeComposite_OnGaugeValue(f32x _fValue);
-
- func void Gauge_SetParam(f32x _fMinValue, f32x _fMaxValue);
- func void GaugeComposite_SetParam(f32x _fMinValue, f32x _fMaxValue, f32x _fIncrement);
-
- // Standard buttons
- // Data class
-
- class Gui_dtGauge
- {
- var f32x fValue; // value from fMinValue to fMaxValue
- var f32x fMinValue;
- var f32x fMaxValue;
-
- var f32x fClampValue; // value from 0.0 to 1.0
-
- var i32x iWidth;
- var i32x iHeight;
-
- var Gui_Component gcContainer;
- var Gui_Component gcTop;
- var Gui_Component gcBottom;
- var Gui_Component gcBackground;
- };
-
-
- class Gui_dtGaugeComposite
- {
- var Gui_Component gcGauge;
- var Gui_Component gcSlider;
- var i32x iHandleSize;
- };
-
-
- // Message
- message GaugeColor(i32x _fColor);
- message GaugeValue(f32x _fValue);
- message GaugeClampValue(f32x _fValue);
-
- message GaugeResize(i32x _iWidth, i32x _iHeight);
- message GaugeParam(f32x _fMinValue, f32x _fMaxValue);
-
- message GaugeCompositeResize(i32x _iSize);
- message GaugeCompositeParam(f32x _fMinValue, f32x _fMaxValue, f32x _fIncrement);
-
-
- // -------------------------------------------------------------
- // -------------------------------------------------------------
-
-
- // Predeclaration
-
-
-
- // Message handling interface
- interface Gui_iGaugeV
- {
-
- GaugeV_OnGaugeValue GaugeValue;
- Gauge_OnGaugeResizeV GaugeResize;
- Gauge_SetParam GaugeParam;
- Gauge_SetColor GaugeColor;
-
- }
-
- interface Gui_iGaugeH
- {
-
- GaugeH_OnGaugeValue GaugeValue;
- Gauge_OnGaugeResizeH GaugeResize;
- Gauge_SetParam GaugeParam;
- Gauge_SetColor GaugeColor;
-
- }
-
- interface Gui_iGaugeCompositeV {
-
- GaugeCompositeV_SldChange SldChange;
- GaugeCompositeV_OnGaugeResize GaugeCompositeResize;
- GaugeComposite_OnGaugeValue GaugeValue;
- GaugeComposite_SetParam GaugeCompositeParam;
- GaugeComposite_OnEnable Enable;
- GaugeComposite_OnDisable Disable;
-
- }
-
- interface Gui_iGaugeCompositeH
- {
-
- GaugeCompositeH_SldChange SldChange;
- GaugeCompositeH_OnGaugeResize GaugeCompositeResize;
- GaugeComposite_OnGaugeValue GaugeValue;
- GaugeComposite_SetParam GaugeCompositeParam;
- GaugeComposite_OnEnable Enable;
- GaugeComposite_OnDisable Disable;
- }
-
-
- // functions
-
- func Gui_Component NewDefaultGaugeCompositeV(i32x _iHeight)
- {
- var Gui_Component composite;
-
- composite=NewGaugeCompositeV(smTrainingDayGauge, smSlider_V, _iHeight);
-
- return(composite);
- }
-
- func Gui_Component NewDefaultGaugeCompositeH(i32x _iWidth)
- {
- var Gui_Component composite;
-
- composite=NewGaugeCompositeH(smHGauge, smSlider_H, _iWidth);
-
- return(composite);
- }
-
-
- /*
- * Function : New Gauge Composite Vertical
- * Parameters : _pGaugeMaterial material for the gauge
- * : _pSliderMaterial material for the slider
- * : _iHeight height of the composite gauge
- */
- func Gui_Component NewGaugeCompositeV(Menu_Material _pGaugeMaterial, Menu_Material _pSliderMaterial, i32x _iHeight)
- {
- var Gui_Component composite;
- var Gui_dtGaugeComposite pdtData;
- var i32x w,h;
-
- composite=NewObject(Gui_iGaugeCompositeV);
-
- pdtData=new Gui_dtGaugeComposite;
- SetData(composite, pdtData);
-
- pdtData.gcSlider=NewSliderV(_pSliderMaterial, _iHeight);
- pdtData.iHandleSize=GetAreaHeight(_pSliderMaterial,e_GUI_State_Enabled);
- Clip(pdtData.gcSlider);
-
- // the width of the gauge composite is the same as the width of the handle of the slider
- w=SizeX(pdtData.gcSlider);
- // the gauge is smaller than the slider (because of the size of the handle)
- h=_iHeight-pdtData.iHandleSize;
-
- pdtData.gcGauge=NewGaugeV(_pGaugeMaterial, w, h);
-
- StretchTo(composite, w, _iHeight);
-
- SetComponentNumber(composite, 2);
- MountComponent(composite, pdtData.gcGauge);
- MountComponent(composite, pdtData.gcSlider);
-
- // moves the gauge in the middle of the component
- MoveTo(pdtData.gcGauge, (SizeX(composite)-SizeX(pdtData.gcGauge))/2, (SizeY(composite)-SizeY(pdtData.gcGauge))/2);
-
- return(composite);
- }
-
- /*
- * Function : New Gauge Composite Horizontal
- * Parameters : _pGaugeMaterial material for the gauge
- * : _pSliderMaterial material for the slider
- * : _iWidth width of the composite gauge
- */
- func Gui_Component NewGaugeCompositeH(Menu_Material _pGaugeMaterial, Menu_Material _pSliderMaterial, i32x _iWidth)
- {
- var Gui_Component composite;
- var Gui_dtGaugeComposite pdtData;
- var i32x w,h;
-
- composite=NewObject(Gui_iGaugeCompositeH);
-
- pdtData=new Gui_dtGaugeComposite;
- SetData(composite, pdtData);
-
- pdtData.gcSlider=NewSliderH(_pSliderMaterial, _iWidth);
- pdtData.iHandleSize=GetAreaWidth(_pSliderMaterial,e_GUI_State_Enabled);
- Clip(pdtData.gcSlider);
-
- // the height of the gauge composite is the same as the height of the handle of the slider
- h=SizeY(pdtData.gcSlider);
- // the gauge is smaller than the slider (because of the size of the handle)
- w=_iWidth-pdtData.iHandleSize;
-
- pdtData.gcGauge=NewGaugeH(_pGaugeMaterial, w, h/2);
- //pdtData.gcGauge<<GaugeColor(MakeARGB(255,255,0,0));
-
- StretchTo(composite, _iWidth, h);
-
- SetComponentNumber(composite, 2);
- MountComponent(composite, pdtData.gcGauge);
- MountComponent(composite, pdtData.gcSlider);
-
- // moves the gauge in the middle of the component
- MoveTo(pdtData.gcGauge, (SizeX(composite)-SizeX(pdtData.gcGauge))/2, (SizeY(composite)-SizeY(pdtData.gcGauge))/2);
-
- return(composite);
- }
-
- /*
- * Function : New Gauge Vertical
- * Parameters : _pMaterial material for the gauge
- * : _iWidth width of the gauge
- * : _iHeight height of the gauge
- */
- func Gui_Component NewGaugeV(Menu_Material _pMaterial, i32x _iWidth, i32x _iHeight)
- {
- var Gui_Component component;
-
- component=NewObject(Gui_iGaugeV);
- InitGaugeCommon(component, _pMaterial, _iWidth, _iHeight);
-
- return(component);
- }
-
-
- /*
- * Function : New Gauge Horizontal
- * Parameters : _pMaterial material for the gauge
- * : _iWidth width of the gauge
- * : _iHeight height of the gauge
- */
- func Gui_Component NewGaugeH(Menu_Material _pMaterial, i32x _iWidth, i32x _iHeight)
- {
- var Gui_Component component;
-
- component=NewObject(Gui_iGaugeH);
- InitGaugeCommon(component, _pMaterial, _iWidth, _iHeight);
-
- return(component);
- }
-
-
- /*
- * Function : Init Gauge Common
- * Parameters : _component the gauge to initialize
- * : _pMaterial material for the gauge
- * : _iWidth width of the gauge
- * : _iHeight height of the gauge
- */
- func Gui_Component InitGaugeCommon(Gui_Component _component, Menu_Material _pMaterial, i32x _iWidth, i32x _iHeight)
- {
- var Gui_dtGauge pdtData;
-
- pdtData=new Gui_dtGauge;
- pdtData.fClampValue=1.0;
- pdtData.fMinValue=0.0;
- pdtData.fMaxValue=1.0;
- pdtData.fValue=1.0;
-
- SetData(_component, pdtData);
- SetComponentNumber(_component, 1);
-
- // Create each bitmap for gauge
- // create a background bitmap
- pdtData.gcBackground=NewBitmap(_pMaterial,1);
- SetAlign(pdtData.gcBackground,e_GUI_HAlign_Zoom,e_GUI_VAlign_Zoom);
- MountComponent(_component,pdtData.gcBackground);
-
- // create a top bitmap
- pdtData.gcTop=NewBitmap(_pMaterial,2);
- SetAlign(pdtData.gcTop,e_GUI_HAlign_Zoom,e_GUI_VAlign_Zoom);
- MountComponent(_component,pdtData.gcTop);
-
- // create a bottom bitmap
- pdtData.gcBottom=NewBitmap(_pMaterial,0);
- SetAlign(pdtData.gcBottom,e_GUI_HAlign_Zoom,e_GUI_VAlign_Zoom);
- MountComponent(_component,pdtData.gcBottom);
-
- // creates a bitmap for the gauge
- pdtData.gcContainer = NewBitmap(_pMaterial, 1);
- SetShadingMode(GetSprite(pdtData.gcContainer),DLC_GouraudMode_ModulateDiffuse,DLC_GouraudMode_ModulateDiffuse);
- Clip(pdtData.gcContainer);
- SetAlign(pdtData.gcContainer, e_GUI_HAlign_Zoom, e_GUI_VAlign_Zoom);
-
- MountComponent(_component, pdtData.gcContainer);
-
- // sends the resize message...
- _component<<GaugeResize(_iWidth, _iHeight);
- }
-
-
- func void GaugeCompositeV_OnGaugeResize(i32x _iSize)
- {
- var Gui_Component pthis;
- var Gui_dtGaugeComposite pdtData;
- var i32x w,h;
-
- pthis=GetThis();
- pdtData=GetData(pthis);
-
- // the width of the gauge composite is the same as the width of the handle of the slider
- w=SizeX(pdtData.gcSlider);
- // the gauge is smaller than the slider (because of the size of the handle)
- h=_iSize-pdtData.iHandleSize;
-
- pdtData.gcGauge<<GaugeResize(w/2, h);
- pdtData.gcSlider<<SldSize(_iSize);
-
- StretchTo(pthis, w, _iSize);
-
- // moves the gauge in the middle of the component
- MoveTo(pdtData.gcGauge, (SizeX(pthis)-SizeX(pdtData.gcGauge))/2, (SizeY(pthis)-SizeY(pdtData.gcGauge))/2);
- }
-
- func void GaugeCompositeH_OnGaugeResize(i32x _iSize)
- {
- var Gui_Component pthis;
- var Gui_dtGaugeComposite pdtData;
- var i32x w,h;
-
- pthis=GetThis();
- pdtData=GetData(pthis);
-
- // the height of the gauge composite is the same as the height of the handle of the slider
- h=SizeY(pdtData.gcSlider);
- // the gauge is smaller than the slider (because of the size of the handle)
- w=_iSize-pdtData.iHandleSize;
-
- pdtData.gcGauge<<GaugeResize(w, h/2);
- pdtData.gcSlider<<SldSize(_iSize);
-
- StretchTo(pthis, _iSize, h);
-
- // moves the gauge in the middle of the component
- MoveTo(pdtData.gcGauge, (SizeX(pthis)-SizeX(pdtData.gcGauge))/2, (SizeY(pthis)-SizeY(pdtData.gcGauge))/2);
- }
-
-
- /*
- * Function : Gauge resize
- * Message : "GaugeResize"
- */
- func void Gauge_OnGaugeResizeH(i32x _iWidth, i32x _iHeight)
- {
- var Gui_Component pthis;
- var Gui_dtGauge pdtData;
-
- pthis=GetThis();
- pdtData=GetData(pthis);
-
- pdtData.iWidth=_iWidth;
- pdtData.iHeight=_iHeight;
-
- // Stretch the composite (the bitmap is resized with the GaugeValue message)
- StretchTo(pthis, pdtData.iWidth, pdtData.iHeight);
-
- // Left border
- StretchTo(pdtData.gcBottom,SizeX(pdtData.gcBottom),_iHeight);
- MoveTo(pdtData.gcBottom,-SizeX(pdtData.gcBottom),0);
-
- // Center part
- StretchTo(pdtData.gcBackground,_iWidth,_iHeight);
-
- // Right border
- StretchTo(pdtData.gcTop,SizeX(pdtData.gcTop),_iHeight);
- MoveTo(pdtData.gcTop,_iWidth,0);
-
- pthis<<GaugeValue(pdtData.fClampValue);
- }
- func void Gauge_OnGaugeResizeV(i32x _iWidth, i32x _iHeight)
- {
- var Gui_Component pthis;
- var Gui_dtGauge pdtData;
-
- pthis=GetThis();
- pdtData=GetData(pthis);
-
- pdtData.iWidth=_iWidth;
- pdtData.iHeight=_iHeight;
-
- // Stretch the composite (the bitmap is resized with the GaugeValue message)
- StretchTo(pthis, pdtData.iWidth, pdtData.iHeight);
-
- // Bottom border
- StretchTo(pdtData.gcBottom,_iWidth,SizeY(pdtData.gcBottom));
- MoveTo(pdtData.gcBottom,0,-SizeY(pdtData.gcBottom));
-
- // Center part
- StretchTo(pdtData.gcBackground,_iWidth,_iHeight);
-
- // Right border
- StretchTo(pdtData.gcTop,_iWidth,SizeY(pdtData.gcTop));
- MoveTo(pdtData.gcTop,0,_iHeight);
-
- pthis<<GaugeValue(pdtData.fClampValue);
- }
-
-
- /*
- * Function : Gauge set value
- * Remarks : Test if value is between min and max
- * Message : "GaugeValue"
- */
- func void GaugeV_OnGaugeValue(f32x _fValue)
- {
- var Gui_Component pthis;
- var Gui_dtGauge pdtData;
-
- pthis=GetThis();
- pdtData=GetData(pthis);
-
- if (_fValue>=pdtData.fMinValue && _fValue<=pdtData.fMaxValue)
- {
- pdtData.fValue = _fValue;
- pdtData.fClampValue = (pdtData.fValue-pdtData.fMinValue)/(pdtData.fMaxValue-pdtData.fMinValue);
-
- // moves the bitmap at the bottom of the component and resizes it
- MoveTo(pdtData.gcContainer, 0, pdtData.iHeight - pdtData.fClampValue*pdtData.iHeight);
- StretchTo(pdtData.gcContainer, pdtData.iWidth, pdtData.fClampValue*pdtData.iHeight);
- }
- }
-
- /*
- * Function : Gauge set value
- * Remarks : Test if value is between 0.0 and 1.0
- * Message : "GaugeValue"
- */
- func void GaugeH_OnGaugeValue(f32x _fValue)
- {
- var Gui_Component pthis;
- var Gui_dtGauge pdtData;
-
- pthis=GetThis();
- pdtData=GetData(pthis);
-
- if (_fValue>=pdtData.fMinValue && _fValue<=pdtData.fMaxValue)
- {
- pdtData.fValue = _fValue;
- pdtData.fClampValue = (pdtData.fValue-pdtData.fMinValue)/(pdtData.fMaxValue-pdtData.fMinValue);
-
- // resizes the bitmap
- StretchTo(pdtData.gcContainer, pdtData.fClampValue*pdtData.iWidth, pdtData.iHeight);
- }
- }
-
-
- func void GaugeComposite_OnEnable()
- {
- var Gui_Component pthis;
- var Gui_dtGaugeComposite pdtData;
-
- pthis=GetThis();
- pdtData=GetData(pthis);
-
- pdtData.gcSlider<<Show();
- }
-
- func void GaugeComposite_OnDisable()
- {
- var Gui_Component pthis;
- var Gui_dtGaugeComposite pdtData;
-
- pthis=GetThis();
- pdtData=GetData(pthis);
-
-
- pdtData.gcSlider<<Hide();
- }
-
- /*
- * Function : Gauge Composite Sld Change
- * Message : "SldChange"
- */
- func void GaugeCompositeV_SldChange(Gui_Component _psource, f32x _fValue)
- {
- var Gui_Component pthis,parent;
- var Gui_dtGaugeComposite pdtData;
- var Gui_dtGauge pdtGauge;
-
- pthis=GetThis();
- pdtData=GetData(pthis);
-
- pdtGauge=GetData(pdtData.gcGauge);
- pdtData.gcGauge<<GaugeValue(pdtGauge.fMaxValue-_fValue+pdtGauge.fMinValue);
-
- parent=GetParent(pthis);
- parent<<SldChange(pthis,pdtGauge.fMaxValue-_fValue+pdtGauge.fMinValue);
- }
-
- /*
- * Function : Gauge Composite Sld Change
- * Message : "SldChange"
- */
- func void GaugeCompositeH_SldChange(Gui_Component _psource, f32x _fValue)
- {
- var Gui_Component pthis,parent;
- var Gui_dtGaugeComposite pdtData;
-
- pthis=GetThis();
- pdtData=GetData(pthis);
-
- pdtData.gcGauge<<GaugeValue(_fValue);
-
- parent=GetParent(pthis);
- parent<<SldChange(pthis,_fValue);
- }
-
- func void Gauge_SetParam(f32x _fMinValue, f32x _fMaxValue)
- {
- var Gui_Component pthis;
- var Gui_dtGauge pdtData;
-
- pthis=GetThis();
- pdtData=GetData(pthis);
-
- pdtData.fMinValue=_fMinValue;
- pdtData.fMaxValue=_fMaxValue;
- pdtData.fValue=_fMinValue+pdtData.fClampValue*(_fMaxValue-_fMinValue);
- }
-
-
- func void GaugeComposite_SetParam(f32x _fMinValue, f32x _fMaxValue, f32x _fIncrement)
- {
- var Gui_Component pthis;
- var Gui_dtGaugeComposite pdtData;
-
- pthis=GetThis();
- pdtData=GetData(pthis);
-
- pdtData.gcGauge<<GaugeParam(_fMinValue, _fMaxValue);
- pdtData.gcSlider<<SldParam( _fMinValue, _fMaxValue, _fIncrement);
- }
-
- func void GaugeComposite_OnGaugeValue(f32x _fValue)
- {
- var Gui_Component pthis;
- var Gui_dtGaugeComposite pdtData;
-
- pthis=GetThis();
- pdtData=GetData(pthis);
-
- pdtData.gcSlider<<QuietSldValue(_fValue);
- pdtData.gcGauge<<GaugeValue(_fValue);
- }
-
- func void Gauge_SetColor(i32x _iColor)
- {
- var Gui_Component pthis;
- var Gui_dtGauge pdtData;
-
- pthis=GetThis();
- pdtData=GetData(pthis);
-
- SetColor(pdtData.gcContainer,_iColor);
- }
-